using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JlPay.Sdk.Core;
using JlPay.Sdk.Services.Marketing;
using JlPay.Sdk.Models.Marketing;

namespace JlPay.Sdk.Examples.Marketing.MerchantActivityAdd
{
    /// <summary>
    /// 商户活动新增独立示例程序
    /// </summary>
    public class MerchantActivityAddDemo
    {
        /// <summary>
        /// 主程序入口
        /// </summary>
        /// <param name="args">命令行参数</param>
        /// <returns>任务</returns>
        public static async Task Main(string[] args)
        {
            Console.WriteLine("==========================================");
            Console.WriteLine("===== 商户活动新增独立示例程序 =====");
            Console.WriteLine("==========================================");
            Console.WriteLine();

            await MerchantActivityAddDemoAsync();

            Console.WriteLine("==========================================");
            Console.WriteLine("===== 示例运行完毕 =====");
            Console.WriteLine("==========================================");
        }

        /// <summary>
        /// 创建配置对象
        /// </summary>
        /// <returns>配置对象</returns>
        private static Config CreateConfig()
        {
            return DemoConfig.CreateConfigWithCrypto();
        }

        /// <summary>
        /// 构建商户活动新增请求
        /// </summary>
        /// <returns>请求对象</returns>
        private static MerchantActivityAddRequest BuildMerchantActivityAddRequest()
        {
            var request = new MerchantActivityAddRequest
            {
                MerchNo = "84940535193A026",
                ActId = "act610000064"
            };

            return request;
        }

        /// <summary>
        /// 商户活动新增示例
        /// </summary>
        public static async Task MerchantActivityAddDemoAsync()
        {
            Console.WriteLine("开始执行商户活动新增示例");
            
            try
            {
                // 创建配置对象和商户活动新增服务
                var config = CreateConfig();
                var merchantActivityAddService = new MerchantActivityAddService(config);
                
                // 创建商户活动新增请求
                var request = BuildMerchantActivityAddRequest();
                
                // 发送请求
                var response = await merchantActivityAddService.MerchantActivityAddAsync(request);
                
                // 处理响应结果
                response.HandleResponse("商户活动新增", config);
            }
            catch (Exception ex)
            {
                var config = CreateConfig();
                var response = new MerchantActivityAddResponse();
                response.HandleResponseWithException("商户活动新增", config, ex);
            }
            
            Console.WriteLine("商户活动新增示例执行完毕");
        }
    }
} 